﻿CREATE TRIGGER tr_Dealer_Insert_Constrains
ON dbo.t_Dealer
FOR INSERT,UPDATE
AS

DECLARE @UsixID sysname
SELECT @UsixID = i.UsixID FROM t_Dealer D INNER JOIN inserted i ON i.UsixID = D.UsixID AND i.ID <> D.ID

IF NOT @UsixID IS NULL BEGIN
	ROLLBACK TRAN
	RAISERROR('Usix ID %s is already assigned to another dealer.',16,1,@UsixID)
	RETURN
END
